﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Billing.Utilities;
using System.Data;
using System.Drawing.Printing;

namespace Billing.Windows
{
    /// <summary>
    /// Interaction logic for DuplicateBill.xaml
    /// </summary>
    public partial class DuplicateBill : Window
    {
        public DuplicateBill()
        {
            InitializeComponent();
            txtBillNo.Focus();
        }

        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                this.Close();
            }
            else if (e.Key == Key.Enter && txtBillNo.Text != string.Empty)
            {
                DataSet ds = Database.GetCompleteBillByBillNo(txtBillNo.Text);
                if (ds != null && ds.Tables.Count == 2 && ds.Tables[0].Rows != null && ds.Tables[0].Rows.Count > 0)
                {
                    NewPrinter form = new NewPrinter(ds);
                    form.printDocument1.PrintController = new StandardPrintController();
                    form.printDocument1.Print();
                    txtBillNo.Clear();
                }

                this.Close();
            }
        }
    }
}
